home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_39760.txt < prev    next >
Text File  |  1991-02-27  |  2KB  |  47 lines

  1. -- card: 39760 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. Another alternative in this case is to declare name to be a character pointer variable rather than an array.  Then it may be assigned the address of a constant array direct- ly or immobile space allocated dynamically with the standard malloc() function*:
  11.  
  12.     void   Person::set(void)
  13.     {
  14.         name = "Jack Knapp";       /* no problem with TC.  OR use... */
  15.         name = malloc((sizeof char) * 80);     /* another approach: dynamic allocation */
  16.         strcpy(name,"Jack Knapp");   /* no problem if name is allocated dynamically */
  17.     }
  18.  
  19. Another circumstance where the handle implementation causes difficulties is when using the standard fread() and fwrite() functions for binary file I/O.  The following syntax is needed in this case.  (A type name given in parentheses is a CAST**.)
  20.  
  21.     HLock(object);       /* Mac Toolbox routine to prevent memory moving */
  22.     items = fread(*(void**) object,(size_t) sizeof(Class),(size_t) 1,file_pointer);
  23.     HUnlock(object);
  24.  
  25.  
  26.  
  27. -- part contents for background part 7
  28. ----- text -----
  29. 126
  30.  
  31. -- part contents for background part 27
  32. ----- text -----
  33. Dynamic memory allocation
  34. Casts for type conversion
  35.  
  36. -- part contents for background part 20
  37. ----- text -----
  38. Dynamic memory allocation - p197
  39.  
  40. -- part contents for background part 29
  41. ----- text -----
  42. 35106
  43. 47191
  44.  
  45. -- part contents for background part 23
  46. ----- text -----
  47. Casts for type conversion - p150